package com.zb.admin.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zb.admin.mapper.AdChannelMapper;
import com.zb.admin.service.AdChannelService;
import com.zb.model.common.PageResult;
import com.zb.model.dto.admin.ChannelDTO;
import com.zb.model.pojo.admin.AdChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class AdChannelServiceImpl implements AdChannelService {

    @Autowired
    private AdChannelMapper adChannelMapper;

    @Override
    public PageResult pageList(ChannelDTO dto) {
        Integer page = dto.getPage();
        Integer pageSize = dto.getPageSize();
        PageHelper.startPage(page, pageSize);
//        用PageInfo对结果进行包装
//        PageInfo<User>userPageInfo=new PageInfo<>(allUser);
        PageInfo<AdChannel> data = new PageInfo<>(adChannelMapper.pageList(dto));
        return PageResult.builder().total(data.getTotal()).rows(data.getList()).build();
    }

    @Override
    public Integer insert(AdChannel channel) {
        channel.setCreatedTime(new Date());
        channel.setIsDefault(1);
        return adChannelMapper.insert(channel);
    }

    @Override
    public Integer update(AdChannel adChannel) {
        return adChannelMapper.update(adChannel);
    }

    @Override
    public Integer deleteById(Integer id) {
        return adChannelMapper.delete(id);
    }

    @Override
    public AdChannel getById(Integer id) {
        return adChannelMapper.getById(id);
    }
}
